package com.ziyun.erp.web.modules.promotion.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.netflix.discovery.converters.Auto;
import com.ziyun.erp.modules.member.entity.UserBaseInfoEntity;
import com.ziyun.erp.modules.member.service.UserBaseInfoService;
import com.ziyun.erp.modules.promotion.service.SendCouponService;
import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author jiangli
 * @date 2018-09-20 15:18
 * 批量发券
 */
@RestController
@RequestMapping("promotion/sendCoupon")
public class SendCouponController {

    @Autowired
    private SendCouponService sendCouponService;
    @Autowired
    private UserBaseInfoService userBaseInfoService;

    @PostMapping("/doBatchSendCoupon")
    public R doBatchSendCoupon(HttpServletRequest request) {
        String sendCouponType = request.getParameter("sendCouponType");
        String couponIds = request.getParameter("couponIds");
        String param = request.getParameter("param");
        String quantity = request.getParameter("quantity");
        String remarks = request.getParameter("remarks");
        return sendCouponService.doBatchSendCoupon(sendCouponType,couponIds,param, quantity, remarks);
    }

    @GetMapping("getCount/{param}/{type}")
    public R getCount(@PathVariable String param,@PathVariable String type) {
        int count=0;
        if ("userType".equals(type)){
            count=  userBaseInfoService.selectCount(new EntityWrapper<UserBaseInfoEntity>().in("user_type",param));
        }else if ("userSource".equals(type)){
            count=  userBaseInfoService.selectCount(new EntityWrapper<UserBaseInfoEntity>().in("user_source",param));
        }else if ("userLevel".equals(type)){
            count =userBaseInfoService.count(param);
        }
        return R.ok().put("count",count);
    }
}